const conf = new (require('conf'))()
const chalk = require('chalk')
const ModuleAPI = require('./../api/module');
const {get} = require("lodash");

async function list(task) {

  const moduleAPI = new ModuleAPI();
  const moduleResp = await moduleAPI.list()

  const modules = get(moduleResp, 'data.items', []);
  console.info(JSON.stringify(modules))
  console.log(
    chalk.blue.bold('Tasks in green are done. Tasks in yellow are still not done.')
  )
  modules.forEach((module, index) => {
    conf.set('module:' + index, module.id);
    console.log(
      chalk.greenBright(`${index}. ${module.icon} ${module.title}`)
    )
  })

}

module.exports = {
  list
};
